package com.servlet.jsp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/jsp/demo02.do")
public class Demo02Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //模拟从Service中查出的List
        List<Person> people = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            people.add(new Person(i, "user" + i, 10 + i));
        }
        //1.先设置请求对象的域属性
        req.setAttribute("people", people);
        //2.通过请求转发，将带有people属性的请求对象，转发到personList.jsp
        //一定要调用forward() 才会转发出去
        req.getRequestDispatcher("/personList.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
